﻿using System;
using System.Collections.Generic;
using System.IO.IsolatedStorage;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;

namespace LightOMator.Model
{
    [DataContract]
    public class Settings
    {
        public enum SettingsStartPage
        {
            single, multiple, saved
        }

        [IgnoreDataMember]
        private static Settings _instance;
        [IgnoreDataMember]
        public static Settings Instance
        {
            get
            {
                if (_instance == null)
                {
                    if (!IsolatedStorageSettings.ApplicationSettings.TryGetValue<Settings>("_settings", out _instance))
                    {
                        _instance = new Settings
                        {
                            StartPage = SettingsStartPage.single,
                            FadeInStartRangeMs = 0,
                            FadeInEndRangeMs = 10 * 1000,
                            KeepOnStartRangeMs = 0,
                            KeepOnEndRangeMs = 10 * 1000
                        };
                    }

                }
                return _instance;
            }
        }


        [DataMember]
        public SettingsStartPage StartPage { get; set; }

        [DataMember]
        public int FadeInStartRangeMs { get; set; }

        [DataMember]
        public int FadeInEndRangeMs { get; set; }

        [DataMember]
        public int KeepOnStartRangeMs { get; set; }

        [DataMember]
        public int KeepOnEndRangeMs { get; set; }

        public void Save()
        {
            IsolatedStorageSettings.ApplicationSettings["_settings"] = this;
            IsolatedStorageSettings.ApplicationSettings.Save();
        }
    }
}
